package com.qiantu.phone.jsbridge;

import android.util.Log;
import android.webkit.JavascriptInterface;

/**
 * Created by TH-WZH .
 * Create Date 2018/8/8
 * ThinkHome4Android
 */

public class AndroidToJs {

    public OnJsToJavaMethodEventListener listener;

    public AndroidToJs(OnJsToJavaMethodEventListener listener){
        this.listener = listener;
    }

    /**
     * 分享到微信好友
     */
    @JavascriptInterface
    public void shareToWechat(String str){
        Log.e("AndroidToJs","shareToWechat----"+str);
        listener.onMethodEvent(OnJsToJavaMethodEventListener.SHARE_TO_WECHAT,str);
    }

    /**
     * 分享到朋友圈
     */
    @JavascriptInterface
    public void shareToMoment(String str){
        Log.e("AndroidToJs","shareToMoment----"+str);
        listener.onMethodEvent(OnJsToJavaMethodEventListener.SHARE_TO_MOMENT,str);
    }

    /**
     * 分享到qq
     */
    @JavascriptInterface
    public void shareToQQ(String str){
        Log.e("AndroidToJs","shareToQQ----"+str);
        listener.onMethodEvent(OnJsToJavaMethodEventListener.SHARE_TO_QQ,str);
    }

    /**
     * 关闭界面
     */
    @JavascriptInterface
    public void toBack(){
        Log.e("AndroidToJs","toBack----");
        listener.onMethodEvent(OnJsToJavaMethodEventListener.TO_BACK,"");
    }

    /**
     * 复制到剪贴板
     * @param str
     */
    @JavascriptInterface
    public void shareToCopy(String str){
        Log.e("AndroidToJs","shareToCopy----"+str);
        listener.onMethodEvent(OnJsToJavaMethodEventListener.COPY_URL,str);
    }

    /**
     * 发送邮件
     */
    @JavascriptInterface
    public void getEmail(String mail){
        Log.e("AndroidToJs","getEmail----"+mail);
        listener.onMethodEvent(OnJsToJavaMethodEventListener.SEND_EMAIL,mail);
    }

    /**
     * 门开关
     */
    @JavascriptInterface
    public void handleOpenDoor(){
        Log.e("AndroidToJs","handleOpenDoor----");
        listener.onMethodEvent(OnJsToJavaMethodEventListener.OPEN_DOOR,"openDoor");
    }

    /**
     * 可视页面
     */
    @JavascriptInterface
    public void handleCloseAnswer (){
        Log.e("AndroidToJs","handleCloseAnswer----");
        listener.onMethodEvent(OnJsToJavaMethodEventListener.CLOSE_ANSWER,"closeAnswer");
    }
    public interface OnJsToJavaMethodEventListener{

        int SHARE_TO_WECHAT = 0;
        int SHARE_TO_MOMENT = 1;
        int SHARE_TO_QQ = 2;
        int TO_BACK = 3;
        int COPY_URL = 4;
        int SEND_EMAIL = 5;
        int OPEN_DOOR = 6;
        int CLOSE_ANSWER = 7;

        void onMethodEvent(int type, String url);
    }

}
